package com.wzy.level.user.userServlet;

import com.wzy.Jdbc封装.pojo.News_user;
import com.wzy.level.user.userService.userService;
import com.wzy.level.user.userServiceImpl.userServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLEncoder;

@WebServlet("/loginServlet")
public class loginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("user1");
        String password = req.getParameter("pass");
        News_user news_user = new News_user(username,password);
        HttpSession session = req.getSession();
        userService userService = new userServiceImpl();
        News_user news_user1 = userService.selectByUsername(username);
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html; charset=utf-8");
        PrintWriter writer = resp.getWriter();
        String mess="";
        if(news_user1.getPassword().equals(password) ){
            session.setAttribute("user",news_user);
            mess="登录成功";
//          resp.sendRedirect(req.getContextPath()+"/index.jsp");
        }else {
            mess="登录失败";
//          resp.sendRedirect(req.getContextPath()+"/Login.jsp");
        }
        writer.println(mess);
        writer.flush();
        writer.close();

    }
}
